import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/load_network_image_widget.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/order_list_controller.dart';

class OrderListView extends GetView<OrderListController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: const AppBarWidget(
            backgroundColor: ColorConfig.white, titleStr: '我的订单'),
        body: Container(
          padding: EdgeInsets.only(top: 10),
          child: Obx(() => ListView.separated(
              itemBuilder: ((context, index) {
                return infoWidget(index);
              }),
              separatorBuilder: ((context, index) {
                return Container(
                  height: 10,
                );
              }),
              itemCount: controller.orderList.length)),
        ));
  }

  infoWidget(index) {
    Map item = controller.orderList[index];
    // "id" -> 1001
// "title" -> "专业采耳"
// "pic" -> "https://iamz.jiliol.net/la/01/b8c37e33defde51cf91e1e03e51657da.png"
// "features" -> "清洁耳道、放松身心"
// "timer" -> "30分钟"
// "price" -> 58
// unm
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 18),
      padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
      decoration: BoxDecoration(
        color: ColorConfig.white,
        // border: Border.all(color: ColorConfig.app_main, width: .5),
        borderRadius: BorderRadius.all(Radius.circular(10.r)),
      ),
      child: Column(
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                clipBehavior: Clip.hardEdge,
                decoration: const BoxDecoration(
                  // border: Border.all(color: ColorConfig.app_main, width: .5),
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                ),
                child: LoadNetworkImageWidget(
                    width: 80, height: 80, imageUrl: item['pic'] ?? ""),
              ),
              const SizedBox(width: 15),
              Expanded(
                child: Container(
                  height: 80,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const SizedBox(height: 5),
                      Row(
                        children: [
                          Text(item['title'] ?? "",
                              style: TextStyle(
                                fontSize: 16.sp,
                                color: ColorConfig.text_label,
                              )),
                          Spacer(),
                          Text("已付款",
                              style: TextStyle(
                                fontSize: 13.sp,
                                color: ColorConfig.app_main,
                              )),
                        ],
                      ),
                      Spacer(),
                      Row(
                        children: [
                          Text(item['name'] ?? "",
                              style: TextStyle(
                                fontSize: 16.sp,
                                color: Color(0xFF5A5A5A),
                              )),
                          if ((item['name'] ?? "").length > 0)
                            const SizedBox(width: 15),
                          Text(item['timer'] ?? "",
                              style: TextStyle(
                                fontSize: 14.sp,
                                color: Color(0xFF5A5A5A),
                              )),
                          const SizedBox(width: 15),
                          Expanded(
                            child: Text('${item['price'] ?? ""}/次',
                                style: TextStyle(
                                  fontSize: 14.sp,
                                  color: Color(0xFF5A5A5A),
                                )),
                          ),
                          Text('x${item['num']}',
                              style: TextStyle(
                                fontSize: 14.sp,
                                color: Color(0xFF5A5A5A),
                              )),
                        ],
                      ),
                      const SizedBox(height: 10),
                    ],
                  ),
                ),
              ),
            ],
          ),
          const SizedBox(height: 10),
          Container(
            width: 1.sw,
            child: Row(
              children: [
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('下单时间：${item['dateTime']}',
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: Color(0xFF5A5A5A),
                          )),
                      const SizedBox(height: 5),
                      Text('实付：${item['price'] * item['num']}元',
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: Color(0xFF5A5A5A),
                          )),
                    ],
                  ),
                ),
                InkWell(
                  onTap: () {
                    Get.toNamed(Routes.EVALUATE,arguments: item);
                  },
                  child: Container(
                    decoration: BoxDecoration(
                      color: ColorConfig.app_main,
                      // border: Border.all(color: ColorConfig.app_main, width: .5),
                      borderRadius: BorderRadius.all(Radius.circular(5.r)),
                    ),
                    padding:
                        const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
                    child: Text('评价',
                        style: TextStyle(
                          fontSize: 15.sp,
                          color: ColorConfig.white,
                        )),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
